/**
 * @version Create on 2012-11-13
 * @author Yinzi Chen
 */

public class PlusOne {

	public int[] plusOne(int[] digits) {
		int n = digits.length;
		digits[n - 1]++;
		for (int i = n - 1; i > 0; --i) {
			if (digits[i] < 10)
				break;
			digits[i - 1] += digits[i] / 10;
			digits[i] %= 10;
		}
		int[] res = null;
		if (digits[0] > 9) {
			res = new int[n + 1];
			res[0] = 1;
			res[1] = digits[0] % 10;
			for (int i = 1; i < n; ++i) {
				res[i + 1] = digits[i];
			}
		} else {
			res = new int[n];
			for (int i = 0; i < n; ++i) {
				res[i] = digits[i];
			}
		}
		return res;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
